package com.jxmcloud.business.cut.service.impl.app.common;

import com.jxmcloud.business.ce.service.ICeSysParameterService;
import com.jxmcloud.business.cut.constants.CutErrorMsg;
import com.jxmcloud.business.cut.dto.client.GetRandomUserInfoDto;
import com.jxmcloud.business.cut.dto.client.SendHeartDto;
import com.jxmcloud.business.cut.dtoCommon.UserInfoDto;
import com.jxmcloud.business.cut.model.database.DBUserLoginInfo;
import com.jxmcloud.business.cut.service.app.common.ICommonService;
import com.jxmcloud.business.cut.service.database.IUserLoginInfoDBService;
import com.jxmcloud.business.cut.vo.client.GetRandomUserInfoVo;
import com.jxmcloud.business.cut.vo.client.SendHeartVo;
import com.jxmcloud.business.cut.vo.user.PlayerInfoVo;
import com.xlcloud.platform.api.exception.BusinessException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Service
public class CommonServiceImpl implements ICommonService {
    @Resource
    private IUserLoginInfoDBService userLoginInfoService;
    @Resource
    private ICeSysParameterService ceSysParameterService;

    /**
     * 根据指定数量获取随机用户信息
     * @param dto
     * @param player
     * @return
     */
    @Override
    public GetRandomUserInfoVo getRandomUserInfo(GetRandomUserInfoDto dto, PlayerInfoVo player) {
        String error = CutErrorMsg.ERROR_TRUE;
        GetRandomUserInfoVo result = new GetRandomUserInfoVo();
        do {
            List<UserInfoDto> list = new ArrayList<>();
            List<DBUserLoginInfo> daoList = userLoginInfoService.lambdaQuery().ne(DBUserLoginInfo::getUid, player.getBase().getUid()).last("ORDER BY RAND() LIMIT " + dto.getCount()).list();
            for (DBUserLoginInfo user : daoList) {
                String nickname = user.getNickName();
                UserInfoDto info = new UserInfoDto();
                info.setAccount(user.getAccount());
                info.setNickName(nickname);
                info.setIcon(user.getIcon());
                list.add(info);
            }
            result.setList(list);
        } while (false);
        if (!error.equals(CutErrorMsg.ERROR_TRUE)) {
            // 抛出异常
            throw new BusinessException(error);
        }
        return result;
    }

    @Override
    public SendHeartVo sendHeart(SendHeartDto dto, PlayerInfoVo player) {
        String error = CutErrorMsg.ERROR_TRUE;
        SendHeartVo result = new SendHeartVo();
        do {


        } while (false);
        if (!error.equals(CutErrorMsg.ERROR_TRUE)) {
            // 抛出异常
            throw new BusinessException(error);
        }
        return result;
    }
}
